Skip to content

Comments

feat: add support for ARMv7 pointers#23

Open
cfung89 wants to merge 2 commits intoRubixDev:mainfrom
cfung89:feat_addresses
Open

feat: add support for ARMv7 pointers#23
cfung89 wants to merge 2 commits intoRubixDev:mainfrom
cfung89:feat_addresses

Conversation

@cfung89
Copy link
Contributor

@cfung89 cfung89 commented Nov 1, 2025

Hello, I found several errors regarding pointers in ARMv7 (or missing features). Here are several examples underlining the different issues that I have attempted to solve.

For LDR A3, [A1, V2]:

Before:

(program ; [0, 0] - [1, 0]
  (instruction ; [0, 0] - [0, 16]
    kind: (word) ; [0, 0] - [0, 3]
    (ident ; [0, 4] - [0, 6]
      (reg ; [0, 4] - [0, 6]
        (word))) ; [0, 4] - [0, 6]
    (ptr ; [0, 8] - [0, 16]
      (ERROR ; [0, 9] - [0, 12]
        (reg ; [0, 9] - [0, 11]
          (word))) ; [0, 9] - [0, 11]
      (reg ; [0, 13] - [0, 15]
        (word))))) ; [0, 13] - [0, 15]

After:

(program ; [0, 0] - [1, 0]
  (instruction ; [0, 0] - [0, 16]
    kind: (word) ; [0, 0] - [0, 3]
    (ident ; [0, 4] - [0, 6]
      (reg ; [0, 4] - [0, 6]
        (word))) ; [0, 4] - [0, 6]
    (ptr ; [0, 8] - [0, 16]
      (reg ; [0, 9] - [0, 11]
        (word)) ; [0, 9] - [0, 11]
      (reg ; [0, 13] - [0, 15]
        (word))))) ; [0, 13] - [0, 15]

Here, only integers were expected in the second argument of the pointer, whereas other registers are also aloud too.


For LDR A3, [A1, V2, LSL#2]:

Before:

(program ; [0, 0] - [1, 0]
  (instruction ; [0, 0] - [0, 7]
    kind: (word) ; [0, 0] - [0, 3]
    (ident ; [0, 4] - [0, 6]
      (reg ; [0, 4] - [0, 6]
        (word)))) ; [0, 4] - [0, 6]
  (ERROR ; [0, 8] - [1, 0]
    (reg ; [0, 9] - [0, 11]
      (word)) ; [0, 9] - [0, 11]
    (word) ; [0, 13] - [0, 15]
    (word) ; [0, 17] - [0, 20]
    (line_comment))) ; [0, 20] - [0, 23]

After:

(program ; [0, 0] - [1, 0]
  (instruction ; [0, 0] - [0, 23]
    kind: (word) ; [0, 0] - [0, 3]
    (ident ; [0, 4] - [0, 6]
      (reg ; [0, 4] - [0, 6]
        (word))) ; [0, 4] - [0, 6]
    (ptr ; [0, 8] - [0, 23]
      (reg ; [0, 9] - [0, 11]
        (word)) ; [0, 9] - [0, 11]
      (reg ; [0, 13] - [0, 15]
        (word)) ; [0, 13] - [0, 15]
      (instruction ; [0, 17] - [0, 20]
        kind: (word)) ; [0, 17] - [0, 20]
      (int)))) ; [0, 20] - [0, 22]

Here, LSL was considered as a register, and #2 as a comment, whereas LSL should be an instruction and #2 should be an integer. This is an ARMv7 feature used to shift the offset of a pointer (if present, the third argument is always some shift instruction followed by an integer).


For: LDR A3, [A2], V3, LSL#2

Before:

(program ; [0, 0] - [1, 0]
  (instruction ; [0, 0] - [0, 21]
    kind: (word) ; [0, 0] - [0, 3]
    (ident ; [0, 4] - [0, 6]
      (reg ; [0, 4] - [0, 6]
        (word))) ; [0, 4] - [0, 6]
    (ptr ; [0, 8] - [0, 12]
      (reg ; [0, 9] - [0, 11]
        (word))) ; [0, 9] - [0, 11]
    (ident ; [0, 14] - [0, 16]
      (reg ; [0, 14] - [0, 16]
        (word))) ; [0, 14] - [0, 16]
    (ident ; [0, 18] - [0, 21]
      (reg ; [0, 18] - [0, 21]
        (word)))) ; [0, 18] - [0, 21]
  (line_comment)) ; [0, 21] - [0, 23]

After:

(program ; [0, 0] - [1, 0]
  (instruction ; [0, 0] - [0, 23]
    kind: (word) ; [0, 0] - [0, 3]
    (ident ; [0, 4] - [0, 6]
      (reg ; [0, 4] - [0, 6]
        (word))) ; [0, 4] - [0, 6]
    (ptr ; [0, 8] - [0, 23]
      (reg ; [0, 9] - [0, 11]
        (word)) ; [0, 9] - [0, 11]
      (reg ; [0, 14] - [0, 16]
        (word)) ; [0, 14] - [0, 16]
      (instruction ; [0, 18] - [0, 21]
        kind: (word)) ; [0, 18] - [0, 21]
      (int)))) ; [0, 21] - [0, 23]

The error here was similar to the 2nd example. However, I added support for post-increment of the register pointer (which is outside of the square brackets).


Thank you very much! Let me know if there are any changes/improvements you would like me to make!

Copy link
Owner

@RubixDev RubixDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to be rebased on main, and I've got a couple of questions, but otherwise looks good :)

@cfung89
Copy link
Contributor Author

cfung89 commented Nov 14, 2025

Thanks for the quick review. I made the requested changes. Let me know if I need to fix anything else!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants